import { GetTreeList, GetTreeData } from '@/services/category';
import { Reducer, Effect } from 'umi';

export interface CateModelType {
    namespace: string;
    state: any;
    effects: {
        getTreeList: Effect;
        getTreeData: Effect;
    };
    reducers: {
        deal: Reducer<any>;
    };
}

const CategoryModel:CateModelType = {
    namespace: 'Category',
    state: {
        response: {},
    },
    effects: {

        * getTreeList({ payload }, { call, put }) {
            const response = yield call(GetTreeList, payload);
            yield put({
                type: 'deal',
                payload: response,
            });
        },

        * getTreeData({ payload }, { call, put }) {
            const response = yield call(GetTreeData, payload);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
    },
    reducers: {
        deal(state, action) {
            return { ...state, response: action.payload };
        },
    },
};
export default CategoryModel;